import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    outDir: 'dist', //指定打包路径，默认为项目根目录下的dist目录
    minify: 'terser', //必须开启：使用terserOptions才有效果
    terserOptions: {
      compress: {
        keep_infinity: true, //防止Infinity被压缩成1/0，这可能会导致chrome上的性能问题
        drop_console: true, //生产环境去除console
        drop_debugger: true, //生产环境去除debugger
      }
    },
    chunkSizeWarningLimit: 1500 //chunk 大小警告的限制（以kbs为单位）
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 3001, 
    open: true, //服务启动时自动在浏览器中打开应用
    overlay: {
      warnings: false,
      errors: true
    },
    proxy: {
      '/dev-api': {
        target: `http://10.86.102.109:8080`, //姚洪云qms本地  
        changeOrigin: true, //开启跨域
        rewrite: path => path.replace(/^\/dev-api/, ''),
      }
    }
  }
})
